#pragma once
#include"nocopy.hpp"
#include "Log.hpp"
#include <cerrno>
#include <cstring>
#include <sys/epoll.h>
class Epoll:public nocopy
{
public:
    Epoll()
    {
        epfd_=epoll_create(1);
        if (epfd_ == -1)
        {
            lg(Error, "epoll_create error: %s", strerror(errno));
        }
        else
        {
            lg(Info, "epoll_create success: %d", epfd_);
        }
    }
    int EpollCtl(int oper,int fd,uint32_t event)
    {
        int n=0;
        if(oper==EPOLL_CTL_DEL)
        {
            n=epoll_ctl(epfd_,oper,fd,nullptr);
        }
        else
        {
            struct epoll_event ev;
            ev.events=event;
            ev.data.fd=fd;
            n=epoll_ctl(epfd_,oper,fd,&ev);
        }
        if(n!=0)
        {
            lg(Error,"epollctl error");
        }
        return n;
    }
    int EpollWait(struct epoll_event revents[], int num)
    {
        int n=epoll_wait(epfd_,revents,num,-1);
        return n;
    }
private:
    int epfd_;
    int _timeout{3000};
};